#include <pcap.h>
#include <stdio.h>
#include <cJSON.h>
int main()
{
cJSON *pObject;
cJSON *pArray;
  char errBuf[PCAP_ERRBUF_SIZE], * device;
	pcap_if_t *alldev;
  
	int ret = pcap_findalldevs(&alldev,errBuf);
	if(ret!=0){
	printf("find failed!\n");
	return 0;
	}

pObject = cJSON_CreateObject();
pArray = cJSON_CreateArray();

  while(alldev)
{
  printf("dev name is:%s\n",alldev->name);
	cJSON_AddItemToArray(pArray,cJSON_CreateString(alldev->name));
	alldev = alldev->next;
}
	cJSON_AddItemToObject(pObject,"DeviceName",pArray);
	char *JsonStr = cJSON_PrintUnformatted(pObject);
	printf("%s\n",JsonStr);
	pcap_freealldevs(alldev);
	printf("%d\n",__LINE__);
	cJSON_Delete(pObject);
	printf("%d\n",__LINE__);
	//cJSON_Delete(pArray);
	printf("%d\n",__LINE__);
  return 0;
}
